package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.EntryMapper;
import com.example.mapper.ResumeClassifyMapper;
import com.example.pojo.Entry;
import com.example.pojo.ResumeClassify;
import com.example.service.IEntryService;
import com.example.util.IdUtils;
import com.example.util.ProKeyGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 入职申请表（未完善） 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-05-16
 */
@Service
public class EntryServiceImpl extends ServiceImpl<EntryMapper, Entry> implements IEntryService {

    @Autowired
    private EntryMapper em;
    @Autowired
    private ResumeClassifyMapper rcm;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer insertEntry(List<Entry> entries) {
        for (Entry entry : entries) {
            ResumeClassify classify = new ResumeClassify();
            classify.setId(entry.getResumeClassId());
            classify.setIsHire(1);
            classify.setIsEntry(1);

            int i = rcm.updateById(classify);
            if (i != 0){
                String ygyz = ProKeyGenerator.generate("YGRZ");
                entry.setProcessId(ygyz);
                entry.setCreateTime(LocalDateTime.now());
                em.insert(entry);
            }
        }
        return 1;
    }
}
